# -*- coding: utf-8 -*-
import requests

class tian_qi:

    def cheng_shi(city):
        req = requests.get(f'http://wthrcdn.etouch.cn/weather_mini?city={city}')
        return req

    def shu_chu(i):
        city_forecast = city_data['forecast'][i]
        print(city_forecast.get('date'))
        print(city_forecast.get('high'))
        print(city_forecast.get('low'))
        print(city_forecast.get('type'))
        fl = city_forecast.get('fengli')
        fx = city_forecast.get('fengxiang')
        print(f'{fx} {fl[-5:-3]}')

while True:
    t = tian_qi
    city = input('输入城市名称\n')
    if not city:
        break
    try:
        req = t.cheng_shi(city)
        # print(req)
    except:
        print('查询失败！')
        break
    dic_city = req.json()
    city_data = dic_city.get('data')
    # print(f'城市信息==========\n{city_data}')

    if city_data:
        city_forecast = city_data['forecast'][0]
        wd = city_data.get('wendu')
        gm = city_data.get('ganmao')
        print(city)
        print(f'温度 {wd}')
        t.shu_chu(0)
        print(f'温馨提示：{gm}')

        for i in range(1, 5):
            t.shu_chu(i)
    else:
        print('未获取')